use std::fmt;


pub struct ConfigMinigrep {
    pub query: String,
    pub filename: String,
    pub file_arr: Vec<String>,
}
pub struct ConfigMinigrepParseError{
    msg: String
}
impl fmt::Display for ConfigMinigrepParseError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        // "provided string was not `true` or `false`".fmt(f)
        self.msg.fmt(f)
    }
}

impl ConfigMinigrep {
    pub fn build (args: &[String]) -> Result<ConfigMinigrep,  ConfigMinigrepParseError> {
        if args.len() < 3 {
            // let a :usize = 3;
            // return Err("参数不足");
            // return Err(3)
            // panic!("参数不足");
            return Err(ConfigMinigrepParseError{
                msg: "参数不足".to_string()
            });
        }
        Ok(ConfigMinigrep {
            query: args[1].clone(),
            filename: args[2].clone(),
            file_arr: args[2..].to_vec(),
        })
    }    
}